Skip list items not being overwritten

I have created a string skip list in which I am saving the target modules for each module in a project.  The issue I'm having is that, although I am saving the same key and value, it appears as though the items are not being overwritten as the manual says they should.  For example, I have multiple modules that link to the same module.  However, when I print out the contents of the skip list, each time I get an additional copy of the same module name.  Here is my code:

Object o;
Link l;
Item itemRef;
Module m;
Skip skTgts = createString;

string tgtMod = "";
string tgtModNames = "";

for itemRef in current Project do {
    modName = name(itemRef);
    fullModName = fullName(itemRef);
    m = read(fullModName, false, true);
    skTgts = createString;      //This line was added to reset the skip list
    for o in m do {
        for l in o -> "*" do {
            tgtMod = target l;
            if (tgtMod != name(itemRef))
                put(skTgts, tgtMod "", tgtMod "");
        }
        ...
        ...
        //Add list of module targets
        for tgtMod in skTgts do {
            if (tgtModNames != "") {
                tgtModNames = tgtModNames "\n";
            }
            tgtModNames = tgtModNames tgtMod;
        }
    }
}

 

Chris


Christopher Cote - Wed Apr 17 14:51:09 EDT 2019

Re: Skip list items not being overwritten
Christopher Cote - Wed Apr 17 15:26:37 EDT 2019

I found the problem...  Another stupid mistake on my part,  I didn't reset tgtModNames each time I looped through the "o in m" loop.

Re: Skip list items not being overwritten
davidcs - Wed Apr 17 15:34:34 EDT 2019

I would reset the skip list using setempty instead of what you are doing. I'm not sure that is the problem but it is odd.

This code looks like a snippet but if you build your list of modules in a loop, which it appears  you are doing, it could have repeated values. 

 

Re: Skip list items not being overwritten
llandale - Fri Apr 19 22:23:33 EDT 2019

Yes, reset the Skip before the "l" Link loop, and reset tgtModNames before the tgtMod Skip loop.

But Woa Nelly!  You really must not concatenate string inside indefinite loops like that; you can easily blow-out your 4gig max memory with useless string-table entries; and DOORS thrashes around, and if you are lucky finally aborts 6 hours later.

Buffer tgtModNames = create()

…

        setempty(tgtModName)

        tgtModName = ""         // This is not always redundant with setempty

        for tgtMod in skTgts do {
            if (length(tgtModNames) != 0) {
                tgtModNames += \n";
            }
            tgtModNames += tgtMod;
        }

       tgtModNameString = stringOf(tgtModNames)

...

delete(tgtModNames)

-Louie

Consider this loop:

string total = ""

int i

for (i=0; i<1000; i++) {total = total "A"}

You end up with "total" being 1000 "A"s, but if I did my math right you also end up with a whopping 500,000 bytes of intermediate results, which DXL does not clean up.  "A" and "AA" and "AAA"... Now try to get your mind around a similar problem featuring a module with 10,000 objects concatenating the name of their target modules...
Appending to a Buffer with "+=" does not create a new string.